

import java.io.*;
import java.util.StringTokenizer;

/*
ID: huangmingbo
LANG: JAVA
TASK: dualpal
*/
public class dualpal {

    public static void main(String[] args) throws IOException {
        try (
                BufferedReader reader = new BufferedReader(new InputStreamReader(dualpal.class.getResourceAsStream(dualpal.class.getSimpleName() + ".in")));
                PrintWriter writer = new PrintWriter(new FileWriter(dualpal.class.getSimpleName() + ".out"));
        ) {

            StringTokenizer stringTokenizer = new StringTokenizer(reader.readLine());
            int lineCount = Integer.parseInt(stringTokenizer.nextToken());
            int minNum = Integer.parseInt(stringTokenizer.nextToken());

            for (int i = minNum + 1; i <= Integer.MAX_VALUE; i++) {
                if(isBaseNum(i)){
                    writer.println(i);
                    if (--lineCount <= 0) {
                        return;
                    }
                }
            }


        }
    }

    private static boolean isBaseNum(int num) {
        int palCount = 0;
        for (int i = 2; i <= 10; i++) {
            if(isPalNum(num, i)) {
                palCount++;
                if (palCount >= 2) {
                    return true;
                }
            }
        }

        return false;
    }

    private static boolean isPalNum(int num, int base) {
        String t = "";
        while (num > 0) {
            t = (num % base) + t;
            num = num / base;
        }

        for (int i = 0; i < t.length() / 2; i++) {
            if (t.charAt(i) != t.charAt(t.length() - 1 -i)) {
                return false;
            }
        }
        return true;
    }
}
